<template>
  <div class="top-category">
    <div class="container">
     <bread>
     <breaditem to="/">首页</breaditem>
     <breaditem>{{category.categorylist.name}}</breaditem>
     </bread>

     <Xtxcarsouel :slides="home.homelist" style="height: 500px" auto-play />
       <div class="sub-list">
  <h3>全部分类</h3>
  <ul>
    <li v-for="item in categorylist.children" :key="item.id">
      <a href="javascript:;">
        <img :src="item.picture" />
        <p>{{ item.name }}</p>
      </a>
    </li>
  </ul>
         </div>
      
      <div v-if="categorylist.children" class="ref-goods" v-for="sub in category.categorylist.children">
  <div class="head">
    <h3>- {{sub.name}} -</h3>
    <p class="tag">温暖柔软，品质之选</p>
    <!-- <XtxMore /> -->
  </div>
  <div class="body">
    <GoodsItem v-for="item in sub.goods" :key="item.id" :goods="item"/>
  </div>
     </div>
      <!-- 股价平 -->
    <div v-else class="ref-goods" v-for="i in 5" :key="i">
        <div class="head">
          <h3><XtxSkeleton :height="40" :width="300" animated /></h3>
          <p class="tag"></p>
          <XtxSkeleton style="position: absolute; right: 20px; top: 40px;" :height="25" :width="100" animated />
        </div>
        <div class="body" style="display: flex; justify-content: space-between;">
          <XtxSkeleton :height="300" :width="200" animated v-for="item in 5" :key="item" />
        </div>
    </div>
      <!-- <XtxSkeleton v-else :height="457" :width="1240" /> -->

   </div>
  </div>

</template>

<script lang="ts" name="TopCategory" setup>
import useStore from '@/store';
import GoodsItem from './components/goods-item.vue'
import { storeToRefs } from 'pinia';
import { watchEffect } from 'vue';
import { useRoute } from 'vue-router';
const { category,home } = useStore()
const route = useRoute()
// watch(()=> route.params.id,()=>{
//   // 坑
//   if(!route.params.id) return
//   category.getTopCategory(route.params.id as string)
// },{
//   immediate:true
// }
// )
watchEffect(() => {
  if (!route.params.id) return
  category.getTopcat()
  category.getTopCategory(route.params.id as string)
})


home.gethomeList()
// Pinia 的解构, 需要配合 storeToRefs 才能保证响应式的特性
const { categorylist } = storeToRefs(category)
</script>

<style scoped lang="less">
.top-category {
  h3 {
    font-size: 28px;
    color: #666;
    font-weight: normal;
    text-align: center;
    line-height: 100px;
  }
  .sub-list {
    margin-top: 20px;
    background-color: #fff;
    ul {
      display: flex;
      padding: 0 32px;
      flex-wrap: wrap;
      li {
        width: 168px;
        height: 160px;
        a {
          text-align: center;
          display: block;
          font-size: 16px;
          img {
            width: 100px;
            height: 100px;
          }
          p {
            line-height: 40px;
          }
          &:hover {
            color: @xtxColor;
          }
        }
      }
    }
  }
  .ref-goods {
    background-color: #fff;
    margin-top: 20px;
    position: relative;
    .head {
      .xtx-more {
        position: absolute;
        top: 20px;
        right: 20px;
      }
      .tag {
        text-align: center;
        color: #999;
        font-size: 20px;
        position: relative;
        top: -20px;
      }
    }
    .body {
      display: flex;
      justify-content: flex-start;
      flex-wrap: wrap;
      padding: 0 65px 30px;
    }
  }
}

 
</style>